function pe15(limit) {
    var matrix = [];
    matrix[0] = 0;
    var getRounteCount = function(i,j) {
        var index = i*(limit+1)+j;
        if(index==0) return 1;
        if(matrix[index]) return matrix[index];
        var count = 0;
        if(checkLimit(i-1,j)) {
            count = count + getRounteCount(i-1, j);
        }
        if(checkLimit(i,j-1)) {
            count = count + getRounteCount(i, j-1);
        }
        matrix[index] = count;
        print("("+i+","+j+")="+matrix[index]);
        return matrix[index];
    }
    
    var checkLimit = function(a,b) {
        return (a>=0 && a<=limit) && (b>=0 && b<=limit);
    }
    
    getRounteCount(0,0);
    getRounteCount(0,1);
    getRounteCount(1,0);
    
    
    for(var round=1; round<=(limit)*2; round++) {
        for(var i=0; i<=round; i++) {
            if(checkLimit(i, round-i)) {
                getRounteCount(i,round-i);
            }
        }
    }
    
    return getRounteCount(limit, limit);
}

var t = new Date().getTime();
pe15(20);
print("Time used: " + (new Date().getTime()-t)/1000 + "s");
